using System;
using System.Collections;
using System.Xml;

using MediaWikiEngine.Domain;

namespace MediaWikiEngine.Command
{
	/// <summary>
	/// Summary description for Bot_Set.
	/// </summary>
	public class Bot_Set : BaseCommand
	{
		public Bot_Set(
			CommandParams param,
			WikiConnection conn)
			:
			base(param, conn)
		{
		}

		/// <summary>
		/// Creates a Bot Set command using an Xml text writer.
		/// </summary>
		/// <param name="inXW"></param>
		/// <param name="inSiteName"></param>
		/// <param name="inUserName"></param>
		/// <param name="inPassword"></param>
		static public void ToXml(
			XmlTextWriter inXW,
			string inSiteName,
			string inUserName,
			string inPassword)
		{
			StartCommandToXml(inXW, "bot:set");

			StartInputToXml(inXW);
			InputNameValueToXml(inXW, "wiki", inSiteName);
			InputNameValueToXml(inXW, "user", inUserName);
			InputNameValueToXml(inXW, "pass", inPassword);
			EndInputToXml(inXW);

			StartOutputToXml(inXW);
			OutputNameValueToXml(inXW, "wiki", "$$wikihost");
			OutputNameValueToXml(inXW, "user", "$$username");
			OutputNameValueToXml(inXW, "pass", "$$password");
			EndOutputToXml(inXW);

			EndCommandToXml(inXW);
		}

		public override CommandResult Execute()
		{
			Hashtable results = new Hashtable();
			foreach (string key in _params.Keys)
				results[key] = _params[key];

			return new CommandResult(results);
		}
	}
}
